package gw.com.android.ui.dialog;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import gw.com.android.model.ConfigType;
import gw.com.android.model.ConfigUtil;
import www.com.library.util.DeviceUtil;

/**
 * 订单超时时提示弹层
 *
 * @author Administrator
 */
public class OrderOutTimeDialog extends BaseDialog implements OnClickListener {

    private boolean exitActivity = true;

    public OrderOutTimeDialog(Context context) {
        super(context);
    }

    public OrderOutTimeDialog(Context context, boolean exitActivity) {
        super(context);
        this.exitActivity = exitActivity;
    }

    /**
     * 显示弹层
     */
    public static void showOrderOutTimeDialog(Activity act) {
        mInstance = new OrderOutTimeDialog(act);
        mInstance.show();
    }

    public static void showOrderOutTimeDialog(Activity act, boolean exitActivity) {
        mInstance = new OrderOutTimeDialog(act, exitActivity);
        mInstance.show();
    }

    @Override
    public void initParam() {
        mCustomViewResId = R.layout.dialog_time_out_content;
        mHasNegButton = false;
        int padding = (int) (15 * DeviceUtil.instance().getScreenDensity(mOwnerAct));
        setPadding(padding, 0, padding, 0);
    }

    @Override
    public void inflaterCustomView(View mCustomView) {
        ((TextView) mCustomView.findViewById(R.id.res_status_content_0))
                .setText(ConfigUtil.instance().getErrorConfigObject().optString(ConfigType.SERVER_ERROR_1011));
        mBtnPos.setOnClickListener(this);
        mBtnPos.setBackgroundResource(R.drawable.dialog_btn_bg_selector);
        setCancelable(false);
    }

    // -------------------------------------------------------------
    // Functions of OnClickListener
    // -------------------------------------------------------------
    @Override
    public void onClick(View v) {
        v.setClickable(false);
        v.setEnabled(false);
        dismiss();
        switch (v.getId()) {
            // 返回
            case R.id.action_btn_pos:
                if (exitActivity) {
                    mOwnerAct.finish();
                }
                break;
        }
    }
}
